<template>
  <template v-for="subItem in menuList" :key="subItem.path">
    <el-sub-menu v-if="subItem.children?.length" :index="subItem.path">
      <template #title>
        <el-icon>
          <component :is="subItem.meta.icon"></component>
        </el-icon>
        <span class="sle">{{ subItem.meta.title }}</span>
      </template>
      <SubMenu :menuList="subItem.children" />
    </el-sub-menu>
    <el-menu-item v-else :index="subItem.path" @click="handleClickMenu(subItem)">
      <el-icon>
        <component :is="subItem.meta.icon"></component>
      </el-icon>
      <template #title>
        <span class="sle">{{ subItem.meta.title }}</span>
      </template>
    </el-menu-item>
  </template>
</template>

<script setup>
import { useRouter } from 'vue-router';

defineProps({
  menuList: {
    type: Array,
    default: () => []
  }
});

const router = useRouter();
const handleClickMenu = (subItem) => {
  if (subItem.meta.isLink) return window.open(subItem.meta.isLink, '_blank');
  router.push(subItem.path);
};
</script>

<style lang="scss">
.fe-log-sub-menu .fe-log-sub-menu__title:hover {
  color: var(--fe-log-menu-hover-text-color) !important;
  background-color: transparent !important;
}
.fe-log-menu--collapse {
  .is-active {
    .fe-log-sub-menu__title {
      color: #ffffff !important;
      background-color: var(--fe-log-color-primary) !important;
    }
  }
}
.fe-log-menu-item {
  &:hover {
    color: var(--fe-log-menu-hover-text-color);
  }
  &.is-active {
    color: var(--fe-log-menu-active-color) !important;
    background: var(--fe-log-menu-active-bg-color) !important;

    // &::before {
    //   position: absolute;
    //   top: 0;
    //   bottom: 0;
    //   width: 4px;
    //   content: "";
    //   background-color: var(--fe-log-color-primary);
    // }
  }
}
.vertical,
.classic,
.transverse {
  .fe-log-menu-item {
    &.is-active {
      &::before {
        left: 0;
      }
    }
  }
}
.columns {
  .fe-log-menu-item {
    &.is-active {
      &::before {
        right: 0;
      }
    }
  }
}
.classic,
.transverse {
  #driver-highlighted-element-stage {
    background-color: #606266 !important;
  }
}
</style>
